package com.spzx.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.common.core.utils.StringUtils;
import com.spzx.user.domain.Region;
import com.spzx.user.mapper.ReginMapper;
import com.spzx.user.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * projectName: spzx-parent
 *
 * @author: 王宝贵
 * time: 2024/10/14 20:12 周一
 * description:
 */
@Service
public class ReginServiceImpl extends ServiceImpl<ReginMapper, Region> implements IRegionService   {

    @Autowired
    private ReginMapper reginMapper;

    /**
     * 根据地区编码 查询城市
     * @param code
     * @return
     */
    @Override
    public String getNameByCode(String code) {
        if(StringUtils.isEmpty(code)){
            return "";
        }

        Region region = reginMapper.selectOne(new LambdaQueryWrapper<Region>()
                .eq(Region::getCode, code).select(Region::getName));
        if(region !=null){
            return region.getName();
        }else {
            return "";
        }

    }

    @Override
    public List<Region> treeSelect(String parentCode) {
        return reginMapper.selectList(new LambdaQueryWrapper<Region>().eq(Region::getParentCode, parentCode));
    }
}